package com.august.service.impl;

import com.august.service.WriteFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

@Service("writeFileService")
public class WriteFileServiceImpl implements WriteFileService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<List> writeFile() {
        //开始时间
        long start = System.currentTimeMillis();
        //返回结果
        List<List> result = new ArrayList<>();

        int count=jdbcTemplate.queryForObject("select count(*) from student", Integer.class).intValue();
        int num = 10000;//每次查询的条数
        //需要查询的次数
        int times=count / num;

        if(count!=0) {
            times=times+1;
        }

        //开始查询的行数
        int startRow = 0;

        List<Callable<List>> tasks = new ArrayList<>();

        for (int i = 1; i < times; i++) {
            //不同的线程用户处理不同分段的数据量，这样就达到了平均分摊查询数据的压力
//            Callable<List<Map<String, Object>>> qfe = new ThredQuery(myService,sex,bindex, num);
//            tasks.add(qfe);
//            bindex=bindex+num;
        }

        //需要查询的次数
       // int times=count / num;

        return result;

    }
}
